<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<jsp:include page="../common/file.jsp" />
<body>
	<script type="text/javascript">
		//初始化滚动条
		$("html").niceScroll({cursorcolor:"#000000",zindex:999999,bouncescroll:true,cursoropacitymax:0.4,cursorborder:"",cursorborderradius:7,cursorwidth:"7px",background:"rgba(0,0,0,.1)",autohidemode:true,railpadding:{top:0,right:2,left:2,bottom:0}});
		//页面信息提示
		var returnMsg = "${_error}";
		var authoriMsg = "${_authoriError}";
	</script>
	<div style="clear: both"></div>
	<div class="main-right-content">
		<div class="main-right-div">
			<div class="main-right-query-div">
			<form id="submit-form-1" action="${pageContext.request.contextPath}/generator/execute" method="post">
				<div class="main-right-search row">
					<div class="col-lg-2">
					&nbsp;&nbsp;&nbsp;&nbsp;表名:<input id="tableName" name="tableName" type="text" class="input-text size-m"
							maxlength="300" placeholder="请输入表名" value="<c:out value='${tableName}'/>" style="width:600px">
					</div>
					<div class="col-lg-2">
					生成路径:<input id="path" name="path" type="text" class="input-text size-m"
							maxlength="50" placeholder="请输入生成路径" value="D:\generator\">
					</div>
					<div class="col-lg-2">
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button type="button" class="btn btn-blue btn-query">生 成</button>
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
			<div class="main-right-table-div">
				<table class="main-right-table">
					<tbody>
					<thead>
						<tr>
							<td style="background-color: #000000; color: white">表字段</td>
							<td style="background-color: #000000; color: white">
								<div class="checkbox check-transparent">
	                            	<input type="checkbox" value="all" id="allchckquery" style="width: 15px;height: 15px">
	                            	<label for="allchck">查询功能</label>
	                            </div>
							</td>
							<td style="background-color: #000000; color: white">
								<div class="checkbox check-transparent">
	                            	<input type="checkbox" value="all" id="allchckcondition" style="width: 15px;height: 15px">
	                            	<label for="allchck">查询条件</label>
	                            </div>
							</td>
							<td style="background-color: #000000; color: white">
								<div class="checkbox check-transparent">
	                            	<input type="checkbox" value="all" id="allchckinsert" style="width: 15px;height: 15px">
	                            	<label for="allchck">新增功能</label>
	                            </div>
							</td>
							<td style="background-color: #000000; color: white">
								<div class="checkbox check-transparent">
	                            	<input type="checkbox" value="all" id="allchckupdate" style="width: 15px;height: 15px">
	                            	<label for="allchck">修改功能</label>
	                            </div>
							</td>
							<td style="background-color: #000000; color: white">
								<div class="checkbox check-transparent">
	                            	<input type="checkbox" value="all" name="allchckdelete" id="allchckdelete" style="width: 15px;height: 15px">
	                            	<label for="allchck">删除功能</label>
	                            </div>
							</td>
							<td style="background-color: #000000; color: white">
								<div class="checkbox check-transparent">
	                            	<input type="checkbox" value="all" id="allchckrequire" style="width: 15px;height: 15px">
	                            	<label for="allchck">是否必填</label>
	                            </div>
							</td>
							<td style="background-color: #000000; color: white">长度限制</td>
						</tr>
					</thead>
						<c:if test="${list != null && list.size() > 0}">
							<c:forEach items="${list}" var="d" varStatus="st">
								<tr>
									<td style="text-align: left; color: black; border: 3px solid rgb(146, 128, 128)">
										<input type="radio" name="ifKey" id="ifKey" value="${d.colName}" style="width: 15px;height: 15px" <c:if test="${st.count == 1}"> checked="checked" </c:if>/>
										${d.colName}&nbsp;&nbsp;&nbsp;&nbsp;(${d.colComment})
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
										<label for="chck${st.count}">查询列表</label>
		                            	<input type="checkbox" class="server" name="checkboxquery" value="${d.colName}#${d.colComment}" id="query${st.count}" style="width: 15px;height: 15px">
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
										<label for="chck${st.count}">查询条件</label>
		                            	<input type="checkbox" class="server" name="checkboxcondition" value="${d.colName}#${d.colComment}" id="condition${st.count}" style="width: 15px;height: 15px">
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
										<label for="chck${st.count}">新增</label>
		                            	<input type="checkbox" class="server" name="checkboxinsert" value="${d.colName}#${d.colComment}" id="insert${st.count}" style="width: 15px;height: 15px">
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
										<label for="chck${st.count}">修改</label>
		                            	<input type="checkbox" class="server" name="checkboxupdate" value="${d.colName}#${d.colComment}" id="update${st.count}" style="width: 15px;height: 15px">
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
										<label for="chck${st.count}">必填</label>
		                            	<input type="checkbox" class="server" name="checkboxrequire" value="${d.colName}#${d.colComment}" id="require${st.count}" style="width: 15px;height: 15px">
									</td>
									<td style="text-align: center; color: black; border: 3px solid rgb(146, 128, 128)">
										<label for="chck${st.count}">长度</label>
		                            	<input type="text" class="server" name="textlength" value="" id="${d.colName}" style="width: 40px" >
									</td>
								</tr>
							</c:forEach>
						</c:if>
						<c:if test="${list == null || list.size() <= 0}">
							<tr>
								<td colspan="8" style="padding: 5px; text-align: center;">查询无记录！</td>
							</tr>
						</c:if>
					</tbody>
				</table>
				</form>
				<form id="submit-form-2" action="${pageContext.request.contextPath}/generator/executeJsp" method="post">
				<input type="hidden" id="queryStr" name="queryStr">
				<input type="hidden" id="conditionStr" name="conditionStr">
				<input type="hidden" id="insertStr" name="insertStr">
				<input type="hidden" id="updateStr" name="updateStr">
				<input type="hidden" id="requireStr" name="requireStr">
				<input type="hidden" id="ifDelete" name="ifDelete">
				<input type="hidden" id="lengthStr" name="lengthStr">
				<input type="hidden" id="ifKeyStr" name="ifKeyStr">
				<input type="hidden" id="tableName2" name="tableName2">
				<input type="hidden" id="path2" name="path2">
				<c:if test="${_error != null && _error != ''}">
					<div style="text-align: center; padding-top: 50px">
						<button type="button" class="btn btn-blue btn-jsp">生成jsp</button>
					</div>
				</c:if>
				</form>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		
		// 生成
		$('.btn-query').click(function() {
			$('#submit-form-1').submit();
		});
		
		// 生成jsp
		$('.btn-jsp').click(function() {
			var queryStr = '';
			$.each($('input[name="checkboxquery"]'),function(){
			    if ($(this).prop('checked')) {
			    	queryStr = queryStr + $(this).val() + '@';
			    }
			});
			$('#queryStr').val(queryStr);
			
			var conditionStr = '';
			$.each($('input[name="checkboxcondition"]'),function(){
			    if ($(this).prop('checked')) {
			    	conditionStr = conditionStr + $(this).val() + '@';
			    }
			});
			$('#conditionStr').val(conditionStr);
			
			var insertStr = '';
			$.each($('input[name="checkboxinsert"]'),function(){
			    if ($(this).prop('checked')) {
			    	insertStr = insertStr + $(this).val() + '@';
			    }
			});
			$('#insertStr').val(insertStr);
			
			var updateStr = '';
			$.each($('input[name="checkboxupdate"]'),function(){
			    if ($(this).prop('checked')) {
			    	updateStr = updateStr + $(this).val() + '@';
			    }
			});
			$('#updateStr').val(updateStr);
			
			var requireStr = '';
			$.each($('input[name="checkboxrequire"]'),function(){
			    if ($(this).prop('checked')) {
			    	requireStr = requireStr + $(this).val() + '@';
			    }
			});
			$('#requireStr').val(requireStr);
			
			var ifDelete = false;
		    if ($('input[name="allchckdelete"]').prop('checked')) {
		    	ifDelete = true;
		    }
		    $('#ifDelete').val(ifDelete);
		    
		    var lengthStr = '';
		    $.each($('input[name="textlength"]'),function(){
			    if ($(this).val() != '') {
			    	lengthStr = lengthStr + $(this).attr('id') + '#' + $(this).val() + '@';
			    }
			});
		    $('#lengthStr').val(lengthStr);
		    
		    $('#tableName2').val($('#tableName').val());
		    $('#path2').val($('#path').val());
		    
		    var	ifKeyStr = $('input[name="ifKey"]:checked').val(); 
		    
		    $('#ifKeyStr').val(ifKeyStr);
		    
			$('#submit-form-2').submit();
		});
		
		// 全选反选
		$(function() {
	    	$('table thead input[id="allchckquery"]').change(function () {
	   			$(this).parents('table').find('tbody input[name="checkboxquery"]').prop('checked', $(this).prop('checked'));
	      	});
	    	
	    	$('table thead input[id="allchckcondition"]').change(function () {
	   			$(this).parents('table').find('tbody input[name="checkboxcondition"]').prop('checked', $(this).prop('checked'));
	      	});
	    	
	    	$('table thead input[id="allchckinsert"]').change(function () {
	   			$(this).parents('table').find('tbody input[name="checkboxinsert"]').prop('checked', $(this).prop('checked'));
	      	});
	    	
	    	$('table thead input[id="allchckupdate"]').change(function () {
	   			$(this).parents('table').find('tbody input[name="checkboxupdate"]').prop('checked', $(this).prop('checked'));
	      	});
	    	
	    	$('table thead input[id="allchckrequire"]').change(function () {
	   			$(this).parents('table').find('tbody input[name="checkboxrequire"]').prop('checked', $(this).prop('checked'));
	      	});

	    });
		
	</script>
</body>
